package com.starhub.domain.annotate.enums;

import lombok.Getter;

/**
 * 格式化数据枚举
 * @version: V1.0
 * @author: liuhf
 * @time 2025-06-19
 */
@Getter
public enum FormatDataEnums {
    SINGLEDATA(0, "[\"aa\",\"bb\",\"cc\"]"),
    MAPDATA(1, "[\"aa\",\"bb\",\"cc\"]");

    private final Integer code;
    private final String formatData;

    FormatDataEnums(Integer code, String formatData) {
        this.code = code;
        this.formatData = formatData;
    }

    /**
     * 根据code获取枚举值
     * @param code
     * @return
     */
    public static FormatDataEnums getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (FormatDataEnums type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        return null;
    }

    /**
     * 根据code获取格式化数据
     * @param code
     * @return
     */
    public static String getFormatDataByCode(Integer code) {
        FormatDataEnums type = getByCode(code);
        return type == null ? "" : type.getFormatData();
    }

    /**
     * 判断code是否有效
     * @param code
     * @return
     */
    public static boolean isValid(Integer code) {
        return getByCode(code) != null;
    }
}
